﻿
CREATE proc [dbo].[proc_Customer_ProtectCheck]
(
	@username nvarchar (50)
)
as
Begin
declare @DepartmentId int,@nUP int,@nSP int,@nUT int,@nST int
set @DepartmentId = (Select DepartmentId From Employee Where UserName=@username)--部门Id
--Select 
--Count(Id)  As UserPCount,
--IsNull((Select ProtectCount From Department Where Id=@DepartmentId),0) As SystemPCount
--From Customer Where ProtectName=@username and ProtectId=2 
	Select @nUP=Count(0),@nSP=IsNull((Select ProtectCount From Department Where Id=@DepartmentId),0)
	From Customer Where ProtectName=@username and ProtectId=2

	Select @nUT=Count(0),@nST=IsNull((Select TrackCount From Department Where Id=@DepartmentId),0)
	From Customer Where ProtectName=@username and ProtectId=4

	Select @nUP As UserPCount,@nSP As SystemPCount,@nUT As UserTCount,@nST As SystemTCount
	Return
End